package com.yanqu.road.server.cmd.curio;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cangbao.CurioProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.curio.CrossCurioMgr;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

@Cmd(code = CrossProtocol.C_CURIO_HISTORY_MAX_SCORE_UPLOAD, desc = "藏品最先达到档位信息上传")
public class CrossCurioUploadHistoryItemScoreCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CurioProto.CrossCurioUploadHistoryItemScoreReqMsg reqMsg = CurioProto.CrossCurioUploadHistoryItemScoreReqMsg.parseFrom(packet.getBytes());

        Map<Integer, BigInteger> scoreMap = new HashMap<>();
        for (CurioProto.CrossCurioMaxScoreTemp scoreTemp : reqMsg.getItemScoreList()) {
            scoreMap.put(scoreTemp.getCurioItemId(), BigInteger.valueOf(scoreTemp.getScore()));
        }

        CrossCurioMgr.changeMaxScoreCondition(serverId, reqMsg.getUserList(), scoreMap);
    }

    @Override
    public void sendData() {

    }
}
